
package View;

import View.SlidePuzzleGUI;
import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author Simon Marshall - jc209673
 */
public class GameTimer {

    /**
     * This class is meant to be part of SlidePuzzleGUI.java
     */
    
    private int counter = 0;
    private SlidePuzzleGUI UI;
    Timer timer;
    private boolean active = false;

    /**
     * 
     * @param GUI - Initializes the GameTimer component in the GUI and updates it whilst the counter is active.
     */
    public GameTimer(SlidePuzzleGUI GUI) {
        UI = GUI;

        timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                if (active == true) {
                    ++counter;
                }
                UI.UpdateTimerLabel(counter);
            }
        }, 0, 1000);
    }

    /**
     * Changes the timer to true after doStart is initialized
     */
    public void doStart() {
        active = true;
    }
    
    /**
     * Stops the game timer from incrementing if the game has being won by the user
     */
    public void doStop() {
        active = false;
    }
    /**
     * Resets the counter to 0 when New Game is pressed and essentially stops the timer from counting until a tile in the game area is clicked on.
     */
    public void doReset() {
        counter = 0;
        active = false;
    }
}
